package com.example.videoplayer.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Configuration
public class StorageConfig {
    
    private static final Logger logger = LoggerFactory.getLogger(StorageConfig.class);
    private final String baseDir = System.getProperty("user.dir");

    @PostConstruct
    public void init() throws IOException {
        // 创建视频目录
        createDirectory(Paths.get(baseDir, "src/main/resources/videos").toString());
        // 创建缩略图目录
        createDirectory(Paths.get(baseDir, "src/main/resources/static/images/thumbnails").toString());
        // 创建 HLS 目录
        createDirectory(Paths.get(baseDir, "src/main/resources/static/hls").toString());
    }

    private void createDirectory(String path) throws IOException {
        Path dirPath = Paths.get(path);
        if (!Files.exists(dirPath)) {
            Files.createDirectories(dirPath);
            logger.info("Created directory: {}", dirPath);
        }
    }
} 